using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using MacomberMap.Common.User_Interfaces.Components;
using System.ComponentModel;
using System.Windows.Forms;
using System.Drawing;
using MacomberMap.Common.User_Interfaces.One_Lines.Elements;
using MacomberMap.Common.Components;
using MacomberMap.Common.Types;
using MacomberMap.Common.Database_Interface;

namespace MacomberMap.Common.User_Interfaces.One_Lines.Elements
{
    /// <summary>
    /// This class provides a viewable Capacitor
    /// </summary>
    public class MM_OneLine_Capacitor : MM_OneLine_Element
    {
        #region Initialization
        /// <summary>
        /// Initialize a new capacitor
        /// </summary>
        /// <param name="DisplayParameters"></param>
        public MM_OneLine_Capacitor(MM_OneLine_Display DisplayParameters)
            : base(DisplayParameters)
        {
        }

        /// <summary>
        /// Initialize a new viewable Capacitor
        /// </summary>
        /// <param name="ElemConfig">The Xml configuration for the Capacitor</param>
        /// <param name="DisplayParameters">The display parameters for the Capacitor</param>
        /// <param name="DbConnection">The database connection</param>
        public MM_OneLine_Capacitor(XmlElement ElemConfig, MM_OneLine_Display DisplayParameters, MM_Database DbConnection)
            : base(ElemConfig, DisplayParameters, DbConnection)
        {
            //Retrieve our arrow direction from the Capacitor
            Orientation = ParseOrientation(ElemConfig.Attributes["Orientation"].Value);                        
        }

        /// <summary>
        /// Initialize a new viewable Capacitor
        /// </summary>
        /// <param name="BaseElement">The CIM element upon which the capacitor is based</param>
        /// <param name="DisplayParameters">The display parameters for the Capacitor</param>
        /// <param name="Orientation">The orientation of the capacitor</param>
        public MM_OneLine_Capacitor(MM_Element BaseElement, MM_OneLine_Display DisplayParameters, MM_OneLine_Element.enumOrientations Orientation)
            : base(BaseElement, DisplayParameters, Orientation)
        {
            //Set up our initial positioning.
            this.Size = new Size(20, 24);
            Orientation = enumOrientations.Up;
            
        }
        #endregion


        #region Rendering
        /// <summary>
        /// Draw the capacitor image
        /// </summary>
        /// <param name="g"></param>
        public override void DrawImage(Graphics g)
        {
            Pen DrawingPen = (KVLevel == null ? Pens.Red : KVLevel.Energized.ForePen);
            Point Center = CenterRect(DisplayRectangle);
            if (Orientation == enumOrientations.Up || Orientation == enumOrientations.Vertical )
            {
                g.DrawLine(DrawingPen, Center.X, 0, Center.X, Height-1);
                g.DrawLine(DrawingPen, 0, 0, Width - 1, 0);
                g.DrawArc(DrawingPen, 0,1, Width-1, Height-1,  180, 180);
            }
            else if (Orientation == enumOrientations.Down)
            {
                g.DrawLine(DrawingPen, Center.X, 0, Center.X, Height - 1);
                g.DrawLine(DrawingPen, 0, Height-1, Width - 1, Height-1);
                g.DrawArc(DrawingPen, 0, -1, Width - 1, Height - 1, 0, 180);
            }             
            else if (Orientation == enumOrientations.Left || Orientation == enumOrientations.Horizontal || Orientation == enumOrientations.Unknown)
            {
                g.DrawLine(DrawingPen, 0, Center.Y, Width - 1, Center.Y);
                g.DrawLine(DrawingPen, 0, 0, 0, Height - 1);
                g.DrawArc(DrawingPen, 1, 0, Width - 1, Height - 1, 90, 180);
            }
            else if (Orientation == enumOrientations.Right)
            {
                g.DrawLine(DrawingPen, 0, Center.Y, Width - 1, Center.Y);
                g.DrawLine(DrawingPen, Width-1, 0, Width-1, Height - 1);
                g.DrawArc(DrawingPen, -1, 0, Width - 1, Height - 1, 270, 180);
            }
       }



        /// <summary>
        /// Draw the Capacitor text
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void TextLabel_Paint(object sender, PaintEventArgs e)
        {
            e.Graphics.DrawString("Text here.", SystemFonts.CaptionFont, Brushes.Aqua, PointF.Empty);
            //throw new Exception("The method or operation is not implemented.");
        }
        #endregion
    }
}


